home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 424_02 / ED-157 / find_char.c < prev    next >
C/C++ Source or Header  |  1993-09-10  |  2KB  |  66 lines

  1. /*
  2.  * Copyright (C) 1992 by Rush Record (rhr@clio.rice.edu)
  3.  * 
  4.  * This file is part of ED.
  5.  * 
  6.  * ED is free software; you can redistribute it and/or modify it under the terms
  7.  * of the GNU General Public License as published by the Free Software Foundation.
  8.  * 
  9.  * ED is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  10.  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11.  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License along with ED
  14.  * (see the file COPYING).  If not, write to the Free Software Foundation, 675
  15.  * Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17. #include "opsys.h"
  18.  
  19. #include "rec.h"
  20. #include "window.h"
  21. #include "ed_dec.h"
  22.  
  23. /******************************************************************************\
  24. |Routine: find_char
  25. |Callby: edit
  26. |Purpose: This routine just checks that the other end of a delete region
  27. |         does not hit the start or end of the buffer.
  28. |Arguments:
  29. |    prepeat is the offset to the other end of the delete region.
  30. \******************************************************************************/
  31. Int find_char(prepeat)
  32. Int prepeat;
  33. {
  34.     register Int curbyt,i;
  35.     register rec_ptr currec;
  36.  
  37.     curbyt = CURBYT;
  38.     currec = CURREC;
  39.     if(prepeat > 0)
  40.     {
  41.         i = prepeat;
  42.         while(currec->length - curbyt < i)
  43.         {
  44.             if(currec == BASE)
  45.                 return(0);
  46.             i -= currec->length - curbyt + 1;
  47.             curbyt = 0;
  48.             currec = currec->next;
  49.         }
  50.     }
  51.     else
  52.     {
  53.         i = -prepeat;
  54.         while(curbyt < i)
  55.         {
  56.             i -= curbyt + 1;
  57.             if(currec->prev == BASE)
  58.                 return(0);
  59.             currec = currec->prev;
  60.             curbyt = currec->length;
  61.         }
  62.     }
  63.     return(prepeat);
  64. }
  65.  
  66.